<?
	class InputDoubleList extends Input
	{
		var $aData;
		var $nMaxLen;     // Limite de la longitud de caracteres de la descripcion ( 0 es sin limite )
		var $nWidth;
		var $nqRows = 5;
		var $cSeparator = ',';
		var $aValues;
	function setValue( $cValues, $cSeparador = ',' )
		{
			$this->cValue = $cValues ;
			$this->aValues = explode( $cSeparador , $cValues ) ;
		}
	function setValueArray( $aValues )
		{
			$this->aValues = $aValues;
		}
	function setRows( $nqRows )
		{
			$this->nqRows = $nqRows;
		}

	function setWidth( $nWidth )
		{
			$this->nWidth = $nWidth;
		}
	function addOption( $cKey, $cValue  )
		{
			$this->aData[] = array( $cKey, $cValue );
		}
	function setMatrix ( $aData )
		{
			$this->aData = $aData;
		}
	function InputDoubleList( $cLabel, $cField, $cValue = '', $bMandatory = false )
		{
			$this->Input($cLabel, $cField, $cValue, $bMandatory );
		}
	function make( )
		{
			$cReturn='<div style="overflow: auto; clear: none">';
			$cPropiedades = $this->getProperties();
			$cWidth = "height: 230px; width: " . ($this->nWidth - 50)/ 2 . "px; ";
			//Separa lo eventos, unos van al select y otros al input hidden
			$cEventosA = $cEventosB = '';
			foreach( $this->aEvents as $cEventName => $cEventFunction )
			{
				if ( $cEventName == 'onchange' )
					$cEventosA.= " $cEventName='javascript: $cEventFunction' ";
				else
					$cEventosB.= " $cEventName='javascript: $cEventFunction' ";
			}

			if ( $this->nqRows ) $cRows  = " size='" . $this->nqRows . "' ";
			$cReturn .= "<select ondblclick='dblListSelect(\"". $this->cField . "\", \"". $this->cField . "_list\", \"". $this->cField . "_select\", false, \"". $this->cSeparator . "\");' style='float: left;$cWidth' multiple $cRows name='". $this->cField . "_list' $cPropiedades $cEventosB id='". $this->cField . "_list' >";
			// Por Cada elemento de la matriz agrega el tag OPTION
			foreach ($this->aData as $aFila )
			{
				list ( $cDataValue, $cDataDescription, $cGroup  )  = $aFila;
				if ( in_array($cDataValue, $this->aValues )  )
				{
					if ( $cGroup && $cGroup != $cGroupAnteriorSeleccion )
					{
						if ( $cGroupAnteriorSeleccion != '' )  $cOptionsSelected .= "</optgroup>";
						$cOptionsSelected .= "<optgroup label='$cGroup' >";
						$cGroupAnteriorSeleccion  = $cGroup ;
					}
					// Agrega el Principio del option ondblclick='dblListMoveItem(\"". $this->cField . "\", \"". $this->cField . "_list\", \"". $this->cField . "_select\", this , \"". $this->cSeparator . "\");'
					$cOptionsSelected .= "<option ";
					// Agrega el Valor del Option
					$cOptionsSelected .= "value='$cDataValue' >";
					// Si Tiene un Limite de caracteres en la Descripcion la recorta, y agrega la Descripcion
					$cOptionsSelected .= $cDataDescription;
					// Agrega el final del option
					$cOptionsSelected .= "</option>";
				} else
				{
					if ( $cGroup && $cGroup != $cGroupAnterior )
					{
						if ( $cGroupAnterior != '' )  $cReturn .= "</optgroup>";
						$cReturn .= "<optgroup label='$cGroup'>";
						$cGroupAnterior  = $cGroup ;
					}
					// Agrega el Principio del option ondblclick='dblListMoveItem(\"". $this->cField . "\", \"". $this->cField . "_list\", \"". $this->cField . "_select\", this , \"". $this->cSeparator . "\");'
					$cReturn .= "<option  ";
					// Agrega el Valor del Option
					$cReturn .= "value='$cDataValue' >";
					// Si Tiene un Limite de caracteres en la Descripcion la recorta, y agrega la Descripcion
					$cReturn .= $cDataDescription;
					// Agrega el final del option
					$cReturn .= "</option>";
				}
			} // Fin por cada Fila de la Matriz
			$cReturn .= "</select>";
			$cReturn .= "<div style='float: left; padding-top: 65px; text-align: center; height: 180px; width: 50px;'>";
			$cReturn .= "<input onclick='dblListSelect(\"". $this->cField . "\", \"". $this->cField . "_list\", \"". $this->cField . "_select\", true, \"". $this->cSeparator . "\");' 	type='button' style='margin-top: 2px; width: 29px; height: 20px; border: none; background-image: url(imagenes/der_todo.gif)' value='' /><br/>";
			$cReturn .= "<input onclick='dblListSelect(\"". $this->cField . "\", \"". $this->cField . "_list\", \"". $this->cField . "_select\",  false, \"". $this->cSeparator . "\");'type='button' style='margin-top: 2px; width: 29px; height: 20px; border: none; background-image: url(imagenes/der_uno.gif)'  value='' /><br/>";
			$cReturn .= "<input onclick='dblListSelect(\"". $this->cField . "\", \"". $this->cField . "_select\", \"". $this->cField . "_list\", false, \"". $this->cSeparator . "\");' type='button' style='margin-top: 2px; width: 29px; height: 20px; border: none; background-image: url(imagenes/izq_uno.gif)'  value='' /><br/>";
			$cReturn .= "<input onclick='dblListSelect(\"". $this->cField . "\", \"". $this->cField . "_select\", \"". $this->cField . "_list\", true, \"". $this->cSeparator . "\");' 	type='button' style='margin-top: 2px; width: 29px; height: 20px; border: none; background-image: url(imagenes/izq_todo.gif)' value='' />";
			$cReturn .= "</div>";
			$cReturn .= "<select  ondblclick='dblListSelect(\"". $this->cField . "\", \"". $this->cField . "_select\", \"". $this->cField . "_list\", false, \"". $this->cSeparator . "\");' style='float: left;$cWidth'  multiple $cWidth $cRows name='". $this->cField . "_select' $cPropiedades $cEventos id='". $this->cField . "_select' >";
			$cReturn .= $cOptionsSelected;
			$cReturn .= "</select>";
			$cReturn .= "<input $cEventosA type ='hidden' name='". $this->cField . "'  id='". $this->cField . "' value='". implode($this->cSeparator, $this->aValues). "' />";
			$cReturn .= "</div>";
			return $cReturn ;
		}
	}
?>
